<?php
/* 
* @Title:  [栏目控制器]
* @Author: {chenlei} [chenleib5@126.com]
* @Date:   2014-04-06 19:54:01
* @Last Modified by:   Administrator
* @Last Modified time: 2014-04-10 17:14:14
* @Copyright:  [hn7m.com]
*/
class ChannelControl extends CommonControl{
	private $model=NULL;
	/**
	 * [__init 自动加载模型类]
	 * @return [type] [description]
	 */
	public function __init(){
		parent::__init();
		$this->model=K('Channel');
	}	
	/**
	 * [index 默认显示栏目列表]
	 * @return [type] [description]
	 */
	public function index(){
		$chan=$this->model->get_data();
		$this->assign('chan',$chan);
		$this->display();
	}
	/**
	 * [add_chan 添加栏目]
	 */
	public function add_chan(){
		if(IS_POST){
			//自动验证类型表数据
			if(!$this->model->create()){
				$this->error($this->model->error);
			}
			//插入类型表
			if(!$this->model->add_data()){
				$this->error('抱歉,栏目添加失败!');
			}
			$this->success('恭喜您,栏目添加成功!',U('index'));
		}
		$this->display();
	}
	/**
	 * [ajax_del_chan ajax删除栏目]
	 * @return [type] [description]
	 */
	public function ajax_del_chan(){
		if(IS_AJAX){
			$nid=Q('nid',0,'intval');
			if($this->model->del_data($nid)){
				$return=array(
					'state'		=>1,
					'message'	=>'已删除,请留意更新该栏目的商品',
					'timeout'	=>3
					);
				$this->ajax($return);
			}
		}
	}
	/**
	 * [ajax_edit_chan AJAX修改栏目]
	 * @return [type] [description]
	 */
	public function ajax_edit_chan(){
		if(IS_AJAX){
			$nid=Q('post.nid',0,'intval');
			$nname=Q('post.nname','','htmlspecialchars');
			$nsort=Q('post.nsort',0,'intval');
			$data=array('nname'=>$nname,'nsort'=>$nsort);
			if($this->model->edit_data($nid,$data)){
				$return=array(
					'state'		=>1,
					'message'	=>'恭喜您,更新成功!',
					'timeout'	=>3	
					);
				$this->ajax($return);
			}
		}
	}
}
?>